/* $Id: BulletedTextView.java 88 2008-01-19 15:49:18Z osborn.steven $
 * 
 * Undroid Package Manager
 *
 * Copyright 2007 Steven Osborn
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.bitsetters.android.common;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 
 * @author Steven Osborn - http://steven.bitsetters.com
 */
public class BulletedTextView extends LinearLayout {

    private TextView mText;
    private TextView mSubText;
    private ImageView mBullet;
    
    /**
     * 
     *
     */
    private class StackedText extends LinearLayout {
        
        private TextView mText;
        private TextView mSubText;
        
        /**
         * 
         * @param context
         * @param text
         * @param subtext
         */
        public StackedText(Context context, String text, String subtext) {
            super(context);
            
            this.setOrientation(VERTICAL);
            
            mText = new TextView(context);
            mSubText = new TextView(context);
                  
            mText.setText(text);
            //mText.setTypeface(Typeface.create("", Typeface.BOLD));
            mSubText.setText(subtext);
            mSubText.setTextSize(12);
            mSubText.setSingleLine(false);
            
            addView(mText, new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

            if(subtext != null) {
                addView(mSubText, new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            }
            
        }
        
    }
	
    /**
     * 
     * @param context
     * @param text
     * @param bullet
     * @param subText
     */
	public BulletedTextView(Context context, String text, Drawable bullet, 
	        String subText) {
	    
	    super(context);
	    
	    this.setOrientation(HORIZONTAL);
	    
	    mBullet = new ImageView(context);
	    mBullet.setImageDrawable(bullet);
	    mBullet.setAdjustViewBounds(true);
	    mBullet.setMaxHeight(32);
	    
	    
	    // left, top, right, bottom
        mBullet.setPadding(10, 5, 10, 0);
        addView(mBullet,  new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        
        StackedText stacked = new StackedText(context,text,subText);

        addView(stacked, new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        
        this.setPadding(0, 5, 0, 5);

	}

	/**
	 * 
	 * @param text
	 */
	public void setSubText(String text) {
	    mSubText.setText(text);
	}
	
	/**
	 * 
	 * @param words
	 */
	public void setText(String words) {
		mText.setText(words);
	}
	
	/**
	 * 
	 * @param bullet
	 */
	public void setBullet(Drawable bullet) {
		mBullet.setImageDrawable(bullet);
	}

}
